<?php
namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;

use App\Models;


class TagController extends Controller
{
    public function tags(Request $request,$keyboard=null){
		
		if($keyboard){
			$tagname = Models\Tag::where('tag_id',$keyboard)->value('tagname');
			$artids = Models\Tag::select('art_id')->where('tagname', 'like', "%{$tagname}%")->pluck('art_id');
			$fronts['tags'] = Models\Art::select('art_id','title','content','tags')->whereIn('art_id', $artids)->simplePaginate(10);
			
			$tdk['title'] = $tagname.' 标签合集_编程语言学习和Web开发教程 | 个人经历和互联网事件分享 - 代码示例网';
			$tdk['keywords'] = $tagname .' 标签合集';
			$tdk['description'] = $tagname.' 标签合集，代码示例网提供编程语言学习和Web开发教程，同时分享个人经历和互联网事件的见解和观点。';
		
		} else {
			$tdk['title'] = '标签合集_编程语言学习和Web开发教程 | 个人经历和互联网事件分享 - 代码示例网';
			$tdk['keywords'] = '标签合集';
			$tdk['description'] = '标签合集，代码示例网提供编程语言学习和Web开发教程，同时分享个人经历和互联网事件的见解和观点。';
			
			$fronts['tags'] = Models\Tag::select('tag_id','tagname')->orderByDesc('tag_id')->groupBy('tagname')->simplePaginate(500);
		}
		
		$fronts['tdk'] = $tdk;
		$fronts['keyboard'] = $tagname??$keyboard;
		
		
		//热点缓存
		if (!Cache()->has('hotarts')) {
			$fronts['hotarts'] = Models\Art::select('art_id','title')->orderByDesc('view')->where([['is_state', '=', '0'],['is_del', '=', '1']])->limit(5)->get()->toArray();
			Cache()->set('hotarts',$fronts['hotarts'],3600);
		}
		$fronts['hotarts'] = Cache()->get('hotarts');
		
		
        return view('front/tag/tags',$fronts);
    }
	

}
